<!-- 删除机构 -->
<template>
  <a-modal v-model:visible="visible" title="删除机构" @cancel="handleCancel" @before-ok="handleBeforeOk" width="700px">
    <div class="penal"> 请确认，是否删除当前机构？ </div>
  </a-modal>
</template>

<script setup>
  import { ref } from 'vue'
  import { orgDelete } from '@/api/organization/organization'
  import { Message } from '@arco-design/web-vue'

  const visible = ref(false)

  const orgId = ref(null)
  const handleClick = (nodeData) => {
    orgId.value = nodeData.id
    visible.value = true
  }

  const handleBeforeOk = (done) => {
    console.log('执行删除操作', done)
    orgDelete({ id: orgId.value }).then((res) => {
      if (res.code == 200) {
        returnOrgId()
        Message.success(res.message)
        visible.value = false
      } else {
        Message.error(res.message)
      }
    })
  }

  // 回传刷新列表
  const emit = defineEmits(['orgDeleteOver', 'delete'])
  const returnOrgId = () => {
    emit('delete')
  }

  const handleCancel = () => {
    visible.value = false
  }

  defineExpose({
    handleClick,
  })
</script>

<style lang="less" scoped>
  .penal {
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
</style>
